<?php
Class Controller_cadeiras Extends Controller_Base
{
	
	
	
	function index() {
		$cadeiras = $this->registry['cadeiras']->lista();
		
		$this->registry['template']->set('contents', $cadeiras);
		$this->registry['template']->show('common/banner');
		$this->registry['template']->show('cadeiras/index');
		$this->registry['template']->show('common/footer');
    }
    
    function adicionar()
    {
    	$extra_scripts = Array();
		array_push($extra_scripts,"<script language='javascript' type='text/javascript' src='/public/ajaxfilemanager/tiny_mce/jscripts/tiny_mce/tiny_mce.js'></script>\n");
		$this->registry['template']->set('extra_scripts', $extra_scripts);
		
		if($_POST)
		{
			$my_res = $this->registry['cadeiras']->adiciona($_POST);
			if($my_res)
			{
				header("location:/suser/cadeiras");
			} else {
				echo "ERRO";
			}
		}
		
		$this->registry['template']->show('common/banner');
		$this->registry['template']->show('cadeiras/adicionar');
		$this->registry['template']->show('common/footer');
    }
    
    function ver()
    {
    	$current_id = $this->registry['Uri']->getURIsegmento(2);
    	if(!$current_id)
    	{
    		header("location:/suser/menu");
    	}
    	$cadeira = $this->registry['cadeiras']->GetById($current_id);
    	if(!$cadeira)
    	{
    		header("location:/suser/menu");
    	}
    	
    	$this->registry['template']->set('cadeira', $cadeira);
    	$this->registry['template']->show('common/banner');
		$this->registry['template']->show('cadeiras/ver');
		$this->registry['template']->show('common/footer');
    }
    
	function remover()
    {
    	$current_id = $this->registry['Uri']->getURIsegmento(2);
    	if(!$current_id)
    	{
    		header("location:/suser/menu");
    	}
    	$cadeira = $this->registry['cadeiras']->GetById($current_id);
    	if(!$cadeira)
    	{
    		header("location:/suser/menu");
    	}
    	if($_POST)
    	{
    		//print_r($_POST);
    		$this->registry['cadeiras']->remove($current_id);
    		header("location:/suser/cadeiras");
    	}
    	$this->registry['template']->set('cadeira', $cadeira);
    	$this->registry['template']->show('common/banner');
		$this->registry['template']->show('cadeiras/remover');
		$this->registry['template']->show('common/footer');
    }
    
	function editar()
    {
    	$current_id = $this->registry['Uri']->getURIsegmento(2);
    	if(!$current_id)
    	{
    		header("location:/suser/menu");
    	}
    	$cadeira = $this->registry['cadeiras']->GetById($current_id);
    	if(!$cadeira)
    	{
    		header("location:/suser/menu");
    	}
    	if($_POST)
    	{
    		//print_r($_POST);
    		$this->registry['cadeiras']->update($current_id, $_POST);
    		header("location:/suser/cadeiras");
    	}
    	$this->registry['template']->set('cadeira', $cadeira);
    	$this->registry['template']->show('common/banner');
		$this->registry['template']->show('cadeiras/editar');
		$this->registry['template']->show('common/footer');
    }
}
?>